/**
 * Created with IntelliJ IDEA.
 * Description:针对locker加锁，但是很少使用
 * User: 东莞呵呵
 * Date:2022-09-10
 * Time:9:50
 */
class Counter2{
    public int sum=0;
    private Object locker=new Object();
    public void increase(){
        synchronized (locker){
            sum++;
        }
    }
}
public class Demo7 {
    public static void main(String[] args) throws InterruptedException {
        Counter2 counter=new Counter2();
        Thread t1 =new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 50000; i++) {
                    counter.increase();
                }
            }
        });
        Thread t2 =new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 50000; i++) {
                    counter.increase();;
                }
            }
        });

        t1.start();
        t2.start();

        t1.join();
        t2.join();

        System.out.println(counter.sum);
    }
}
